package day02;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.tribes.util.Arrays;

/**
 * 演示http请求
 * 
 * HttpServletRequest
 * 
 * @author hchaojie
 *
 */
public class DemoRequest extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		// 获取请求参数, 参数是通过key=value形式传过来的，我们可以根据key取到value
//		String name = request.getParameter("name");
//		System.out.println(name);
//		
//		String password = request.getParameter("password");
//		System.out.println(password);
//		
		// 包含了所有的请求参数
		Map<String, String[]> map = request.getParameterMap();
		for (Entry<String, String[]> entry : map.entrySet()) {
			System.out.println("key:" + entry.getKey() + " value:" + Arrays.toString(entry.getValue()));
		}
		

		// 获取多选框请求参数，这种方式只能获取一个
		String skills = request.getParameter("skills");
		System.out.println(skills);
		
		// 获取多选框请求参数：
		String[] strings = request.getParameterMap().get("skills");
		System.out.println(Arrays.toString(strings));
	}
}
